package com.wili.c.asm;
import com.wili.c.Class9;
/**
 * 
 * @author weila 2021年3月7日
 */
public interface CodeFilter {
	boolean doCode(int opcode, Object... infos);
}
interface PutFieldFilter extends CodeFilter {
	/**
	 * see com.sun.org.apache.bcel.internal.Const.PUTSTATIC
	 */
	static final int PUTSTATIC = 179;

	static final int PUTFIELD = 181;

	static final int GETFIELD = 180;

	static final int GETSTATIC = 178;
	/**
	 * 	过滤动作、过滤名称并处理（如：加入集合）	
	 */
	default boolean doCode(int opcode, Object... infos) {
		Object owner;
		String field;
		int lineNo;
		Class<?> cls;
		int type;
		if (opcode == PUTFIELD//181 
				|| opcode == PUTSTATIC) {//179
			type = 1;
		} else if (opcode == GETFIELD//180 
				|| opcode == GETSTATIC) {//178
			type = 2;
		} else {
			return false;
		}
		owner = infos[0];
		field = (String) infos[1];
		lineNo = (Integer) infos[2];
		if (owner instanceof Class) {
			cls = (Class<?>) owner;
		} else {
			cls = Class9.forName(owner.toString().replace("/", "."), -1);
		}
		if (cls.isArray()) {
			cls = Class9.bottomTypeOf(cls);
		}
		return doField(type, cls, field, lineNo);
	};

	/**
	 * 
	 */
	boolean doField(int type, Class<?> cls, String field, int lineNo);
}